package crud.dao;

import crud.dao.pojo.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper     //mybatis标记,这是一个需要被spring框架扫描并创建代理实现类的接口
public interface UserInfoDao {
    // 添加用户
    @Insert("insert into users_info(first_name, last_name, phone, email) "
            + "values(#{firstName},#{lastName},#{phone},#{email})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void add(UserInfo ui);

    //更新用户
    @Update("update users_info set first_name=#{firstName},last_name=#{lastName}," +
            "phone=#{phone}, email=#{email} where id=#{id}")
    void update(UserInfo ui);

    //删除用户
    @Delete("DELETE FROM users_info WHERE id = #{id}")
    void delete(UserInfo ui);

    //计数
    @Select("select count(*) from users_info")
    int count();

    //查询所有用户
    @Select("select id, first_name as firstName, last_name as lastName, phone, email from users_info")
    List<UserInfo> allUsers();
}
